<?php
/**
 * Created by PhpStorm.
 * User: yuyj
 * Date: 16-12-16
 * Time: 下午5:42
 */

namespace common\repositories\common;


use common\entities\myhtsq\ApplicationInfoEntity;
use common\entities\myhtsq\ContractApplicationEntity;
use common\repositories\BaseRepository;

class MyscrmContractApplicationRepository extends BaseRepository
{
    public function getContractApplicationByContractId($contractId)
    {
        return ContractApplicationEntity::find()
            ->select([
                'myscrm_contract_application.contract_application_id',
                'myscrm_contract_application.application_id',
                'myscrm_contract_application.authorization_type',
                'myscrm_contract_application.authorization_numeric',
                'myscrm_contract_application.contract_type',
                'myscrm_contract_application.rent_period',
                'myscrm_contract_application.amount',
                'application_name' => 'myscrm_application_info.show_name',
            ])
            ->leftJoin(ApplicationInfoEntity::tableName(), 'myscrm_application_info.application_id=myscrm_contract_application.application_id')
            ->where(['contract_id' => $contractId])
            ->asArray()
            ->all();
    }


    /**
     * 获取签约产品的ID
     *
     * @param $contractId
     * @param $applicationId
     * @return bool|string
     */
    public static function getContractApplicationId($contractId, $applicationId)
    {
        $map['contract_id']     = $contractId;
        $map['application_id']  = $applicationId;

        //sonar 坏味道修复
        return ContractApplicationEntity::find()->where($map)->select('contract_application_id')->scalar();

    }
}